package com.yh.daoimpl;



import com.yh.dao.StudentDao;
import com.yh.javabean.Student;
import com.yh.util.MyJdbcUtil;

import java.util.ArrayList;

/**
 * @Auther: Liang
 * @Date: 2024/4/1 - 04 - 01 - 19:09
 * @Description: com.sms.daoimpl
 * @version: 1.0
 */
public class StudentDaoImpl implements StudentDao {

    @Override
    public ArrayList<Student> selectByUsernameAndPassword(String username, String password) {
        String sql ="select * from student where username=? and password=?";
        return MyJdbcUtil.dql(Student.class,sql,username,password);
    }

    @Override
    public int updateTidBysid(int sid, int tid) {
        String sql="update student set tid=? where sid=?";
        return MyJdbcUtil.dml(sql,tid,sid);
    }

    @Override
    public ArrayList<Student> selectBysid(int sid) {
        String sql="select * from student where sid=?";
        return MyJdbcUtil.dql(Student.class,sql,sid);
    }

    @Override
    public int updateScoreBysid(int sid, double score) {
        String sql="update student set score=? where sid=?";
        return MyJdbcUtil.dml(sql,score,sid);
    }

    @Override
    public ArrayList<Student> selectBytid(int tid) {
        String sql="select * from student where tid=?";
        return MyJdbcUtil.dql(Student.class,sql,tid);
    }

    @Override
    public ArrayList<Student> selectByTidAndStatus(int tid, int status) {
        String sql="select * from student where tid =? and status=?";
        return MyJdbcUtil.dql(Student.class,sql,tid,status);
    }

    @Override
    public int updatStatusBysid(int sid, int status) {
        String sql="update student set status=? where sid=?";
        return MyJdbcUtil.dml(sql,status,sid);
    }

    @Override
    public int updatStatusBytid(int tid, int status) {
        String sql="update student set status=? where tid=?";
        return MyJdbcUtil.dml(sql,status,tid);

    }

    @Override
    public int insert(Student student) {
        String sql ="insert into student (username,password,name) values (?,?,?)";
        return MyJdbcUtil.dml(sql,student.getUsername(),student.getPassword(),student.getName());
    }

    @Override
    public int deleteBysid(int sid) {
        String sql ="delete from student where sid=?";
        return MyJdbcUtil.dml(sql,sid);
    }

    @Override
    public int updatePasswordBySid(int sid, String password) {
        String sql="update student set password=? where sid=?";
        return MyJdbcUtil.dml(sql,password,sid);
    }
}
